/**
 * 
 */
package org.vidyakiran.app.test.util;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;

import org.vidyakiran.app.server.dao.util.DatabaseUtils;
import org.vidyakiran.app.server.domain.reference.City;
import org.vidyakiran.app.server.domain.reference.UserType;

/**
 * @author Harpreet
 *
 */
public class ReferenceDataLoader {

	private EntityManager em;
	
	public void loadReferenceData() {
		
		for (Object obj : getObjectsToLoad()) {
			em = DatabaseUtils.startTransaction(em);
			try {
				em.persist(obj);
				em.getTransaction().commit();
			} finally {
				DatabaseUtils.cleanupTransaction(em);
			}
		}
	}
	
	private List<Object> getObjectsToLoad() {
		List<Object> referenceList = new ArrayList<Object>();
		referenceList.addAll(getCityReference());
		referenceList.addAll(getUserTypeReference());
		
		return referenceList;
	}
	
	/** City Table reference data
	 * @return
	 */
	private List<City> getCityReference(){
		List<City> cityList = new ArrayList<City>();
		City city1 = new City();
		city1.setName("Mumbai");
		cityList.add(city1);
		
		return cityList;
	}
	
	private List<UserType> getUserTypeReference() {
		List<UserType> userTypeList = new ArrayList<UserType>();
		UserType userType1 = new UserType();
		userType1.setName("VOLUNTEER");
		userTypeList.add(userType1);
		
		UserType userType2 = new UserType();
		userType2.setName("ADMIN");
		userTypeList.add(userType2);
		
		return userTypeList;
	}
}
